package org.gap.wizards.creature;

import org.gap.wizards.utils.Persistence;
import org.gap.wizards.views.ViewPlatform.Color;

public class Description {
	private static final String DESCRIPTION_GROUP = "description";
	private static final String COLOR = "color";
	private static final String SYMBOL = "symbol";
	private static final String NAME = "name";

	public static final Description DOG = new Description(Color.BROWN, "d", "dog");
	public static final Description KITTEN = new Description(Color.WHITE, "k", "kitten");
	
	private Color color;
	private String symbol;
	private String name;

	public Description() {
		// Used by persistence.
	}
	
	public Description(Color color, String symbol, String name) {
		this.color = color;
		this.symbol = symbol;
		this.name = name;
	}

	public Color getColor() {
		return color;
	}

	public String getSymbol() {
		return symbol;
	}

	public String getName() {
		return name;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null || !obj.getClass().equals(Description.class)) {
			return false;
		}
		Description other = (Description)obj;
		return color == other.color && symbol.equals(other.symbol) && name.equals(other.name);
	}

	public void persist(Persistence persister) {
		persister.beginSection(DESCRIPTION_GROUP);
		persister.set(COLOR, color.name());
		persister.set(SYMBOL, symbol);
		persister.set(NAME, name);
		persister.endSection();
	}
	
	public void load(Persistence persister) {
		persister.beginSection(DESCRIPTION_GROUP);
		color = Color.valueOf(persister.getString(COLOR));
		symbol = persister.getString(SYMBOL);
		name = persister.getString(NAME);
		persister.endSection();
	}
}
